;(function () {
  var priceList = new Vue({
    el:'#priceList',
    data:{
			curPage: 1,                  // 当前页
      limit: ['10'],                   // 每页条数
      pageLimits:  [{name: '10', code: '10'}, {name: '15', code: '15'}, {name: '20', code: '20'}],      // 分页条数
      project: [],
      projectId: [],
			buildingObj: [],
      permissions: JSON.parse(localStorage.getItem('permissions'))
    },
    filters: {
      formatDate: function (time) {
        if (!time) return '--'
        return hlDateUtil.formatUTCDate(time, 'yyyy-MM-dd')
      },
      formatUndefined: function (item) {
				if (!item) return '--'
        return item
      },
    },
    methods:{
      // 获取项目数据
      getProjectData () {
        hlhttp.get({
          url:'user/projects',
          success: (data) => {
						data = hlArrayUtil.removeRepeat(data, 'projectId');
						this.project = hlArrayUtil.replaceData(data, [{key: 'projectName', rKey: 'name'}, {key: 'projectId', rKey: 'code'}]);
            this.projectId = [data[0].projectId];
            this.projectName = data[0].projectName;
						this.buildingDt()
          }
        })
      },
			//获取楼宇
			buildingDt () {
				hlhttp.get({
					url: 'project/buildings/_search',
					data: {project_id: this.projectId[0], page: this.curPage, limit: this.limit[0]},
					success: (data) => {
						this.buildingObj = data;
						$("#page").initPage(data.totalPage, this.curPage, (n) => {
						  if (this.curPage == n) {
						    return
						  }
						  this.curPage = n;
						  this.buildingDt();
						});
					}
				})
			},
			//选择楼宇
			selBuildingDt (item) {
				this.projectId = [item[0].projectId];
				this.projectName = item[0].projectName;
				this.buildingDt()
			},
			//每页显示数量
			showPages (item) {
				this.curPage = 1;
				this.limit = [item[0].code];
				this.buildingDt()
			},
			//重置
			resetDt () {
				this.curPage = 1;
				this.limit = ['10'];
				this.projectId = [this.project[0].projectId];
				this.projectName = this.project[0].projectName;
				this.buildingDt()
			},
			//新增编辑
			toUrl (item) {
				hlUrlUtil.goTo('buildingAdd', {ddtab:true, buildingId: item.buildingId, projectId: item.projectId}, true)
			}
    },
    mounted:function () {
      hlSelectUi()
      this.getProjectData()
    }
  })
}())
